<?php
/**
 * Created by JiangJiaCai.
 * User: Administrator
 * Date: 2017/9/23 0023
 * Time: 16:25
 */

namespace ext\fun;

use App\Models\QdcsArticle;
use App\Models\QdcsProject;
use Illuminate\Support\Facades\DB;

/**
 * quickly help fun
 * Class Helper
 * @package ext\fun
 */
class Helper
{
    public static function GA(int $classId, $limit, $where = [])
    {
        return QdcsArticle::whereNull('img')->where(array_merge([
            'cls_id' => $classId
        ], $where))->limit($limit)->orderBy('created_at', 'desc')->get();
    }

    public static function GAImg(int $classId, $limit, $where = [])
    {
        return QdcsArticle::whereNotNull('img')->where(array_merge([
            'cls_id' => $classId
        ], $where))->limit($limit)->orderBy('created_at', 'desc')->get();
    }

    public static function GPRO(int $classId, $limit, $where = [])
    {
        return QdcsProject::whereNull('img')->where(array_merge([
            'ptype_id' => $classId
        ], $where))->limit($limit)->orderBy('created_at', 'desc')->get();
    }

    public static function GPROImg(int $classId, $limit, $where = [])
    {
        return QdcsProject::whereNotNull('img')->where(array_merge([
            'ptype_id' => $classId
        ], $where))->limit($limit)->orderBy('created_at', 'desc')->get();
    }

    public static function GAImgNews(){
        $ids = [];
        $clsList =DB::table('qdcs_class')->where('parent_id' , '=' , 34)->get(['id']);
        foreach ($clsList as $v){
            array_push($ids , $v->id);
        }
        return QdcsArticle::whereIn('cls_id' , $ids)->whereNotNull('img')->limit(3)->get();
    }
}